<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 1] 1.3 Compiling a Java Source File</TITLE>
<META NAME="author" CONTENT="Mark Grand">
<META NAME="date" CONTENT="Thu Jul 31 13:05:18 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="java">
<META NAME="title" CONTENT="Java Language Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Language Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 1<br>Introduction</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JLR2-CH-1-SECT-3">1.3 Compiling a Java Source File</A></h2>

<P CLASS=para>
The interface for the Java compiler in Sun's Java Development
Kit (JDK) is the command line. To compile a Java program, run the
program <I CLASS=emphasis>javac</I>
with the name of the source file specified as a command-line argument.
For example, to compile the "Hello World" program, issue
the following command:

<DIV CLASS=screen>
<P>
<PRE>
C:\&gt; javac HelloWorld.java
</PRE>
</DIV>

<P CLASS=para>
The Java compiler, <I CLASS=emphasis>javac</I>, requires that
the name of a Java source file end with a <I CLASS=emphasis>.java</I>
extension. If the source file contains a class or interface that
is declared with the keyword <tt CLASS=literal>public</tt>, the filename
must be the name of that class or interface. There can be at
most one such class or interface in a source file.

<P CLASS=para>
In an environment such as Windows 95 that does not distinguish between
uppercase and lowercase letters in a filename, you still need to be sure
that the case of the filename exactly matches the case used in the
<tt CLASS=literal>public</tt> class or interface declaration. If you use
a filename with the incorrect case, the compiler will be able to compile
the file but it will complain about an incorrect filename.

<P CLASS=para>
The compiler produces a compiled class file with the same
name as the <tt CLASS=literal>public</tt> class or interface declaration;
the file extension used for a compiled
Java file is <I CLASS=emphasis>.class</I>.

<P CLASS=para>
If the <I CLASS=emphasis>javac</I> compiler complains that
it is unable to find some classes, it may mean that an environment
variable named <tt CLASS=literal>CLASSPATH</tt> has not been set properly.
The exact setting needed for <tt CLASS=literal>CLASSPATH</tt> varies
depending on the operating system and its directory structure. However,
the value of <tt CLASS=literal>CLASSPATH</tt> always specifies a list
of directories in which the compiler should search for Java classes.

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch01_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>New Language Features in Java 1.1</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Running a Java Application</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
